<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<jsp:include page="../commons/top.jsp" />
<script type="text/javascript" src="<c:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
<style type="text/css">
.dialog{
	position: fixed;
	_position:absolute;
	z-index:1;
	top: 50%;
	left: 50%;
	margin: -200px 0 0 -300px;
	width: 600px;
	height:350px;
	border:1px solid #CCC;
	line-height: 20px;
	background-color:#F4F4F4;
	overflow:hidden;
	text-align:center;
	padding: 10px;
}	
</style>
<script type="text/javascript">
	//查询
	function logSearch(){
		
		$("#timeTaskLogForm").attr("action","<c:url value="/timetask/list" />");
		$("#timeTaskLogForm").submit();
	}
	//重置
	function logReset() {
		
		window.location.href = "<c:url value="/timetask/list" />?pageNo="+1;
	}
	// 重跑批次
	function rerun(date){
		$.ajax({
	    type: "post",
	    url: "<c:url value="/timetask/rerun"/>",
	    data: {date:date},
	    dataType: "json",
	    success: function(data){
	   	 if(data.result == "success"){
	   		 alert("批次运行成功");
	   	 }
	   	 else if(data.result == "date_error"){
	   		 alert("系统异常");
	   	 }
	   	 else if(data.result == "fail"){
	   		 alert("批次运行失败");
	   	 }
	   	window.location.href = "<c:url value="/timetask/list" />?pageNo="+1;
	   	}
		});
	}
	// 详细信息
	function detailMessage(id){
		var content =  "<div style=\"width:600px;height:325px;text-align:left;margin-bottom: 5px;overflow:auto;\">" 
		+ $("#"+id).val() + "</div>"
		+ "<input type=\"button\" onclick=\"colseDailog()\" value=\"关闭\">";
		$("#detailMessage").html(content);
		$("#detailMessage").show();
	}
	function colseDailog(){
		$("#detailMessage").hide();
	}
	// 执行报表批次
	function reportRun(){
		$.ajax({
	    type: "post",
	    url: "<c:url value="/timetask/manualRun"/>",
	    data: {beginDate:$("#beginDate").val(), endDate:$("#endDate").val()},
	    dataType: "json",
	    success: function(data){
	   	 if(data.result == "success"){
	   		 alert("批次运行成功");
	   	 }
	   	 else if(data.result == "date_error"){
	   		 alert("请填写正确的日期");
	   	 }
	   	 else if(data.result == "fail"){
	   		 alert("批次运行失败");
	   	 }
	    }
		});
	}
</script>
<div id="detailMessage" class="dialog" style="display: none;"></div>
<div id="breadCrumbDiv">
	<span class="main_title"><a href="main.html">首页</a></span>
	<span class="main_title"><a href="#">报表批次</a></span>
	<span class="main_title"><a href="#">日终日结</a></span>
</div>
<div id="workAreaDiv">
	<div id="organizationListDiv">
		<form id="timeTaskLogForm" action="" method="post">
		<table border="0" cellpadding="0" cellspacing="0" width="100%" class=""> 
	    <tr> 
	    	<td class="table_title">查询</td> 
	    </tr> 
	    <tr> 
      	<td> 
      		<table width="100%" cellpadding="1" cellspacing="1" border="0" class="table_border"> 
          	<tr class="table_display_1"> 
	            <td width="10%" class="table_display_2">开始日期</td> 
	            <td width="20%">
	            	<input id="beginDate" name="beginDate" style="width:100px;" value="${param.beginDate}"
	            		class="Wdate" onclick="WdatePicker({dateFmt:'yyyy/MM/dd',readOnly:true})">
	            </td> 
              <td width="10%" class="table_display_2">结束日期</td> 
              <td width="20%">
              	<input id="endDate" name="endDate" style="width:100px;" value="${param.endDate}"
              		class="Wdate" onclick="WdatePicker({dateFmt:'yyyy/MM/dd',readOnly:true})">
	            </td>
           	</tr> 
           </table>
        </td> 
      </tr> 
    	<tr align="right" class="btnTR"> 
	      <td> 
	      	<input type="button" onclick="logSearch()" value="<spring:message code="button.search"></spring:message>">&nbsp;
		      <input type="button" onclick="logReset()" value="<spring:message code="button.reset"></spring:message>"/>&nbsp;
		      <input type="button" onclick="reportRun()" value="<spring:message code="button.run"></spring:message>">
	      </td> 
    	</tr> 
    </table>
    </form>
    <br/> 
		<table border="0" cellpadding="0" cellspacing="0" width="100%" class=""> 
			<tr> 
				<td class="table_title" colspan="2">批次信息</td>
			</tr>
			<tr class="btnTR">
				<td align="right"> 
					<jsp:include page="../commons/page.jsp" flush="true">
						<jsp:param name="url" value="/timetask/list" />
						<jsp:param name="formId" value="timeTaskLogForm"/>
					</jsp:include>
				</td>
			</tr> 
			<tr> 
				<td colspan="2"> 
					<table width="100%" cellpadding="1" cellspacing="1" border="0" class="table_border"> 
						<tr class="table_header_on" align="center">
							<td>操作</td>
							<td>批次日期</td>
							<td>批次名称</td>
							<td>状态</td>
							<td>开始时间</td>
							<td>结束时间</td>
							<td>运行信息</td>
						</tr> 
						<c:if test="${!empty logList}">
							<c:forEach items="${logList}" var="log">
								<tr class="table_display_1">
									<td align="center">
										<c:if test="${log.state == 0}">
											<a href="#" onclick="rerun('<fmt:formatDate value="${log.createDate}" pattern="yyyy/MM/dd"/>')">重跑</a>
										</c:if>
									</td>
									<td align="center"><fmt:formatDate value="${log.createDate}" pattern="yyyy/MM/dd"/></td>
									<td align="center"><c:out value="${log.reportName}"></c:out></td>
									<td align="center">
										<c:choose>
											<c:when test="${log.state == 0}"><span style="color: red;">失败</span></c:when>
											<c:when test="${log.state == 1}"><span style="color: green;">成功</span></c:when>
										</c:choose>
									</td>
									<td align="center"><fmt:formatDate value="${log.beginTime}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
									<td align="center"><fmt:formatDate value="${log.endTime}" pattern="yyyy/MM/dd HH:mm:ss"/></td>
									<td><a href="#" onclick="detailMessage('<fmt:formatDate value="${log.createDate}" pattern="yyyyMMdd"/>')">
										${fn:substring(log.content,0,15)}${fn:length(log.content)>15?'...':''}</a>
										<textarea id="<fmt:formatDate value="${log.createDate}" pattern="yyyyMMdd"/>" 
											style="display: none;"><c:out value="${log.content}"></c:out></textarea>
									</td>
								</tr>
							</c:forEach>
						</c:if>
					</table> 
				</td> 
			</tr> 
		</table> 
	</div>
</div>
<jsp:include page="../commons/bottom.jsp" />